package com.example.friend.controller.exam;

import com.example.common.core.Controller.BaseController;
import com.example.common.core.domin.R;
import com.example.common.core.domin.TableDataInfo;
import com.example.friend.domain.exam.dto.ExamQueryDTO;

import com.example.friend.service.exam.IExamService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/exam")
@Tag(name = "C端竞赛管理接口")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    //semiLogin表示半登录状态即可访问(游客访问)
    //接口地址: /exam/semiLogin/list
    @GetMapping("/semiLogin/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        return getTableDataInfo(examService.list(examQueryDTO));
    }

    //接口地址: /exam/semiLogin/redis/list
    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO) {
        return examService.redisList(examQueryDTO);
    }

    //获取当前竞赛收到题目id
    //接口地址: /exam/getFirstQuestion
    //redis list 数据类型 key: e:q:l: + examId  value:questionId
    @GetMapping("/getFirstQuestion")
    public R<String> getFirstQuestion(Long examId) {
        //代码逻辑: 获取竞赛中题目的顺序列表  排在第一个的题目返回给前端
        //可以copy Question上下题的实现
        return R.ok(examService.getFirstQuestion(examId));
    }

    //题目顺序列表: 先查redis,redis没数据,从mysql中同步过去
    //上一题 -- 参数当前题目id和竞赛id(锁定竞赛列表)
    @GetMapping("/preQuestion")
    public R<String> preQuestion(Long examId,Long questionId) {
        return R.ok(examService.preQuestion(examId,questionId));
    }

    //下一题 -- 参数当前题目id和竞赛id(锁定竞赛列表)
    @GetMapping("/nextQuestion")
    public R<String> nextQuestion(Long examId,Long questionId) {
        return R.ok(examService.nextQuestion(examId,questionId));
    }
}
